<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>pthread_create</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_007_1315">&nbsp;</a>NAME</h4><blockquote>
pthread_create - thread creation
</blockquote><h4><a name = "tag_000_007_1316">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="pthread.h.html">pthread.h</a>&gt;

int pthread_create(pthread_t *<i>thread</i>, const pthread_attr_t *<i>attr</i>,
    void *(*<i>start_routine</i>)(void*), void *<i>arg</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_007_1317">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>pthread_create()</i>
function is used to create a new thread, with attributes specified by
<i>attr</i>,
within a process.
If
<i>attr</i>
is NULL,
the default attributes are used.
If the attributes specified by
<i>attr</i>
are modified later, the thread's attributes are not affected.
Upon successful completion,
<i>pthread_create()</i>
stores the ID of the created thread in the location referenced by
<i>thread</i>.
<p>
The thread is created executing
<i>start_routine</i>
with
<i>arg</i>
as its sole argument.
If the
<i>start_routine</i>
returns, the effect is as if there was an implicit call to
<i><a href="pthread_exit.html">pthread_exit()</a></i>
using the return value of
<i>start_routine</i>
as the exit status.
Note that the thread in which
<i>main()</i>
was originally invoked differs from this.
When it returns from
<i>main()</i>,
the effect is as if there was an implicit call to
<i><a href="exit.html">exit()</a></i>
using the return value of
<i>main()</i>
as the exit status.
<p>
The signal state of the new thread is initialised as follows:
<ul>
<p>
<li>
The signal mask is inherited from the creating thread.
<p>
<li>
The set of signals pending for the new thread is empty.
<p>
</ul>
<p>
If
<i>pthread_create()</i>
fails, no new thread is created
and the contents of the location referenced by
<i>thread</i>
are undefined.
</blockquote><h4><a name = "tag_000_007_1318">&nbsp;</a>RETURN VALUE</h4><blockquote>
If successful, the
<i>pthread_create()</i>
function returns zero.
Otherwise, an error number is returned to indicate the error.
</blockquote><h4><a name = "tag_000_007_1319">&nbsp;</a>ERRORS</h4><blockquote>
The 
<i>pthread_create()</i>
function will fail if:
<dl compact>

<dt>[EAGAIN]<dd>
The system lacked the necessary resources to create another thread,
or the system-imposed limit on the total number of threads
in a process PTHREAD_THREADS_MAX would be exceeded.

<dt>[EINVAL]<dd>
The value specified by
<i>attr</i>
is invalid.

<dt>[EPERM]<dd>
The caller does not have appropriate permission to set the required
scheduling parameters or scheduling policy.

</dl>
<p>
The
<i>pthread_create()</i>
function will not return an error code of [EINTR].
</blockquote><h4><a name = "tag_000_007_1320">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1321">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1322">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1323">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="pthread_exit.html">pthread_exit()</a></i>,
<i><a href="pthread_join.html">pthread_join()</a></i>,
<i><a href="fork.html">fork()</a></i>,
<i><a href="pthread.h.html">&lt;pthread.h&gt;</a></i>.
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from the POSIX Threads Extension (1003.1c-1995)
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

